export const TimeLength = (OldDate: Date) => {
  //  获取当前时间
  const newDate = new Date();
  //用当前时间减去过去时间
  const num = newDate.getTime() - OldDate.getTime();
  let year = Math.floor(num / (1000 * 60 * 60 * 24 * 365));
  let day = Math.floor(num / (1000 * 60 * 60 * 24));
  let hour = Math.floor(num / (1000 * 60 * 60));
  let minutes = Math.floor(num / (1000 * 60));
  let seconds = Math.floor(num / 1000);
  if (year > 0) {
    return `${year}年${day}天`;
  } else if (day > 0) {
    return `${day}天`;
  } else if (hour > 0) {
    return `${hour} 小时`;
  } else if (minutes > 0) {
    return `${minutes}分钟`;
  } else if (seconds > 0) {
    return `${seconds}秒`;
  }
};

export const Time = (Date: Date) => {
  let y = "";
  y = Date.getFullYear() + "";
  let m = "";
  m = Date.getMonth() + 1 + "";
  parseInt(m) <= 9 ? (m = "0" + m) : m;
  let d = "";
  d = Date.getDate() + "";
  parseInt(d) <= 9 ? (d = "0" + d) : d;
  return `${y}年-${m}月-${d}日`;
};

export const TimeDetails = (Date: Date) => {
  let y = "";
  y = Date.getFullYear() + "";
  let m = "";
  m = Date.getMonth() + 1 + "";
  parseInt(m) <= 9 ? (m = "0" + m) : m;
  let d = "";
  d = Date.getDate() + "";
  parseInt(d) <= 9 ? (d = "0" + d) : d;
  let h = Date.getHours() + "";
  parseInt(h) <= 9 ? (h = "0" + h) : h;
  let M = Date.getMinutes() + "";
  parseInt(M) <= 9 ? (M = "0" + M) : M;
  let s = Date.getSeconds() + "";
  parseInt(s) <= 9 ? (s = "0" + s) : s;
  return `${y}-${m}-${d} ${d}:${M}:${s}`;
};
